package com.dog.basics.api.controller.mtkj;


import cn.afterturn.easypoi.entity.vo.TemplateExcelConstants;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.view.PoiBaseView;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.mtkj.ApiBasketAddDto;
import com.dog.basics.bean.dto.api.mtkj.ApiBasketEditDto;
import com.dog.basics.bean.dto.api.mtkj.ApiShoppingCarVo;
import com.dog.basics.bean.vo.api.mtkj.ApiBasketVo;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.security.util.SecurityUtils;
import com.dog.basics.service.mtkj.IMtBasketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 购物车 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@RestController
@RequestMapping("/api/basket")
@Api(value = "购物车模块", tags = SwaggerConstants.API_ALL)
@AllArgsConstructor
public class MtBasketController {
    private final IMtBasketService mtBasketService;
    /**
     * @Description: 测试
     * @Param: page
     * @return: IPage<DeviceCodeVo>
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @GetMapping("/cs")
    @ApiOperation(value = "测试", notes = "测试", tags = SwaggerConstants.API_MY)
    @Inner
    @ApiIgnore
    public void test1(HttpServletRequest request,
                      HttpServletResponse response) {
        ModelMap modelMap=new ModelMap();
                TemplateExportParams params = new TemplateExportParams(
                "templates/专项支出用款申请书_map.xls");
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("date", "2014-12-25");
        map.put("money", 2000000.00);
        map.put("upperMoney", "贰佰万");
        map.put("company", "执笔潜行科技有限公司");
        map.put("bureau", "财政局");
        map.put("person", "JueYue");
        map.put("phone", "1879740****");
        modelMap.put(TemplateExcelConstants.FILE_NAME, "用户信息");
        modelMap.put(TemplateExcelConstants.PARAMS, params);
        modelMap.put(TemplateExcelConstants.MAP_DATA, map);
        PoiBaseView.render(modelMap, request, response,
                TemplateExcelConstants.EASYPOI_TEMPLATE_EXCEL_VIEW);
    }
    /**
     * @Description: 分页购物车列表
     * @Param: BasketFromDto
     * @return: IPage<BasketVo>
     * @Author: wph
     * @Date:
     */
    @ApiOperation(value = "购物车列表", notes = "购物车列表", tags = SwaggerConstants.API_BASKET)
    //@ApiImplicitParam(name = "ids", value = "购物车ID", dataType = "List<Long>", required = true)
    @GetMapping
    public R<List<ApiShoppingCarVo>> page() {
        return R.ok(mtBasketService.getPageList());
    }
    /**
     * @Description: 增加购物车
     * @Param: UserAddrAddDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @PostMapping
    @ApiOperation(value = "增加购物车", notes = "增加购物车", tags = SwaggerConstants.API_BASKET)
    public R<Boolean> saveObj(@Valid @RequestBody ApiBasketAddDto obj) {
        return R.ok(mtBasketService.saveObj(obj));
    }
    /**
     * @Description: 修改购物车
     * @Param: UserAddrAddDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @PutMapping
    @ApiOperation(value = "修改购物车", notes = "修改购物车", tags = SwaggerConstants.API_BASKET)
    public  R<Boolean> editObj(@Valid @RequestBody ApiBasketEditDto obj) {
        return R.ok(mtBasketService.editObj(obj));
    }
    /**
     * @Description: 删除购物车
     * @Param: UserAddrAddDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/3/27 0027
     */
    @DeleteMapping
    @ApiOperation(value = "删除购物车", notes = "删除购物车", tags = SwaggerConstants.API_BASKET)
    @ApiImplicitParam(name = "ids", value = "购物车ID", dataType = "List<Long>", required = true)
    public  R<Boolean> deleteObj(@RequestBody List<Long> ids) {
        return R.ok(mtBasketService.deleteObj(ids));
    }
}
